import { GSprite } from "../../../../../com/mui/controls/GSprite";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { ObjCreate } from "../../common/ObjCreate";
import { ImagesConst } from "../../../resource/ImagesConst";
import { BaseItem } from "../../common/BaseItem";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { TilePanel } from "../../equipment/TilePanel";
import { OpenSeverNewGoodRender } from "./OpenSeverNewGoodRender";
import { ScrollPolicy } from "../../../../../fl/controls/ScrollPolicy";
import { Language } from "../../../../../extend/language/Language";
import { GTextFormat } from "../../../../common/GTextFormat";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { DailySpecialInfo } from "../../../model/DailySpecialInfo";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { CutDataUtil } from "../../../../common/tools/CutDataUtil";
import { Cache } from "../../../cache/Cache";
import { GiftBagConfig } from "../../../resource/GiftBagConfig";
import { CareerUtil } from "../../common/util/CareerUtil";
import { DailyRule } from "../../../rules/DailyRule";
import { DataProvider } from "../../../../../fl/data/DataProvider";
import { FilterConst } from "../../../../component/gconst/FilterConst";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { ScaleBitmap } from "../../../../../com/mui/display/ScaleBitmap";
import { _info } from "../../../../../this/_info";
import { _index } from "../../../../../this/_index";
type int = number;
//class OpenSeverNewRewardItem
    
    export  class OpenSeverNewRewardItem extends GSprite
    {
        constructor()
        {
            super();
            this._rewardsArr = [];
            this.arr = [];
            this.initUI();
            return;
        }

        /* internal  */onOptBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._info) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.DailySpecialGetRewardReq, {"info": _info, "index": _index}));
            }
            return;
        }

        protected initUI(): void
        {
            this._bigItemBg = ObjCreate.createBg(15, 0, 65, 65, this, ImagesConst.PackItemBg);
            this._bigItem = new BaseItem();
            this._bigItem.move(17, 2);
            this._bigItem.setSize(60, 60);
            addChild(this._bigItem);
            this._condTxt = ObjCreate.createTextField("", 87, 1, 280, 40, this, GlobalStyle.textFormat6);
            this._condTxt.multiline = true;
            this._condTxt.wordWrap = true;
            addChild(this._condTxt);
            this._rewardList = new TilePanel();
            this._rewardList.columnWidth = 42;
            this._rewardList.rowHeight = 40;
            this._rewardList.move(87, 24);
            this._rewardList.setStyle("skin", new Object /* flash.display.Bitmap */());
            this._rewardList.setStyle("cellRenderer", OpenSeverNewGoodRender);
            this._rewardList.horizontalScrollPolicy = ScrollPolicy.OFF;
            this._rewardList.verticalScrollPolicy = ScrollPolicy.OFF;
            addChild(this._rewardList);
            this._optBtn = ObjCreate.createGButton(Language.getString(20935), 385, 35, 70, 22, this, "ButtonRedMini");
            this._optBtn.enabled = false;
            this._optBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onOptBtnClickHandler);
            addChild(this._optBtn);
            var loc1=new GTextFormat("", 12, GlobalStyle.color1Uint);
            loc1.align = flash.text.TextFormatAlign.CENTER;
            this._optTxt = ObjCreate.createTextField("", 360, 20, 115, 20, this);
            this._optTxt.defaultTextFormat = loc1;
            this._optTxt.autoSize = flash.text.TextFieldAutoSize.CENTER;
            this._optTxt.multiline = true;
            this._optTxt.wordWrap = true;
            this._line = GlobalClass.getBitmap(ImagesConst.SplitLine);
            this._line.width = this.width;
            addChild(this._line);
            return;
        }

        public updateData(arg1: DailySpecialInfo, arg2: int): void
        {
            var loc2=null;
            var loc4=0;
            this.clear();
            this._info = arg1;
            this._index = arg2;
            this._condTxt.htmlText = HTMLUtil.addColor(CutDataUtil.getStringValueWithoutsharp(arg1.specialActiveInfo.condDesc)[arg2], GlobalStyle.color6);
            this._bigItem.itemData = arg1.rewardDataList[arg2][0];
            var loc1=Cache.instance.role.entityInfo.career;
            this._rewardsArr = GiftBagConfig.instance.getInfoByType(this._bigItem.itemData.itemCode);
            var loc3=[];
            var loc5=0;
            var loc6=this._rewardsArr;
            for(loc2 of loc6) 
            {
                if (!(loc2.type == 3 && CareerUtil.isCareerSuit(loc2.career, loc1))) 
                {
                    continue;
                }
                loc3.push(loc2);
            }
            this.arr = [];
            loc4 = 0;
            while (loc4 < loc3.length) 
            {
                if (loc3[loc4].item) 
                {
                    this.arr.push(loc3[loc4]);
                }
                ++loc4;
            }
            if (arg1.rewardGetRule != DailyRule.SpecialDailyRewardForShow) 
            {
                this._getRule = false;
            }
            else 
            {
                this._getRule = true;
            }
            if (this._getRule) 
            {
                if (this.arr.length > 8) 
                {
                    this._rewardList.setSize(375, 90);
                    this._line.y = 110;
                }
                else 
                {
                    this._rewardList.setSize(375, 45);
                    this._line.y = 72;
                }
            }
            else if (this.arr.length > 6) 
            {
                this._rewardList.setSize(280, 90);
                this._line.y = 110;
            }
            else 
            {
                this._rewardList.setSize(280, 45);
                this._line.y = 72;
            }
            this._rewardList.dataProvider = new DataProvider(this.flyBack(this.arr));
            this._rewardList.drawNow();
            if (arg1.rewardGetRule != DailyRule.SpecialDailyRewardGetBtn) 
            {
                if (contains(this._optBtn)) 
                {
                    removeChild(this._optBtn);
                }
                if (!contains(this._optTxt)) 
                {
                    addChild(this._optTxt);
                }
                if (arg1.rewardGetRule != DailyRule.SpecialDailyRewardGetMail) 
                {
                    if (arg1.rewardGetRule != DailyRule.SpecialDailyRewardGetAtOnce) 
                    {
                        if (arg1.rewardGetRule != DailyRule.SpecialDailyRewardForShow) 
                        {
                            this._optTxt.htmlText = HTMLUtil.addColor(Language.getString(21048), GlobalStyle.color1);
                        }
                        else 
                        {
                            this._optTxt.htmlText = "";
                        }
                    }
                    else 
                    {
                        this._optTxt.htmlText = HTMLUtil.addColor(Language.getString(70920), GlobalStyle.color1);
                    }
                }
                else 
                {
                    this._optTxt.htmlText = HTMLUtil.addColor(Language.getString(21031), GlobalStyle.color1);
                }
            }
            else 
            {
                if (contains(this._optTxt)) 
                {
                    removeChild(this._optTxt);
                }
                if (!contains(this._optBtn)) 
                {
                    addChild(this._optBtn);
                }
            }
            return;
        }

        /* internal  */flyBack(arg1: Array<any>, arg2: Boolean=false): Array<any>
        {
            var loc1=[];
            var loc2={};
            var loc3=0;
            while (loc3 < arg1.length) 
            {
                (loc2 = {}).info = arg1[loc3];
                loc2.flyFlag = arg2;
                loc1.push(loc2);
                ++loc3;
            }
            return loc1;
        }

        public onGetRewardRes(): void
        {
            this._rewardList.dataProvider = new DataProvider(this.flyBack(this.arr, true));
            if (this._optBtn) 
            {
                this._optBtn.enabled = false;
            }
            return;
        }

        public updataGetRewardState(arg1: int): void
        {
            if (this._optBtn) 
            {
                var loc1=arg1;
                switch (loc1) 
                {
                    case 0:
                    {
                        this._optBtn.enabled = false;
                        this._optBtn.label = Language.getString(70903);
                        this._optBtn.enabled = false;
                        this._optBtn.filters = [FilterConst.colorFilter];
                        break;
                    }
                    case 1:
                    {
                        this._optBtn.enabled = true;
                        this._optBtn.label = Language.getString(70908);
                        this._optBtn.enabled = true;
                        this._optBtn.filters = [];
                        break;
                    }
                    case 2:
                    {
                        this._optBtn.enabled = false;
                        this._optBtn.label = Language.getString(70918);
                        this._optBtn.enabled = false;
                        this._optBtn.filters = [FilterConst.colorFilter];
                        break;
                    }
                }
            }
            return;
        }

        protected clear(): void
        {
            this._info = null;
            this._index = -1;
            this._optBtn.enabled = false;
            this._rewardList.dataProvider.removeAll();
            return;
        }

        public /* override */ dispose(arg1: Boolean=true): void
        {
            this.clear();
            super.dispose(arg1);
            return;
        }

        public /* override */ get height(): number
        {
            if (this._getRule) 
            {
                if (this.arr.length > 8) 
                {
                    return 116;
                }
                return 83;
            }
            if (this.arr.length > 6) 
            {
                return 116;
            }
            return 83;
        }

        public /* override */ get width(): number
        {
            return 465;
        }

        /* internal */ /* var */_condTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_optBtn: GButton;

        /* internal */ /* var */_optTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_info: DailySpecialInfo;

        /* internal */ /* var */_index: int;

        /* internal */ /* var */_line: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_rewardList: TilePanel;

        /* internal */ /* var */_bigItemBg: ScaleBitmap;

        /* internal */ /* var */_bigItem: BaseItem;

        /* internal */ /* var */_rewardsArr: Array<any>;

        /* internal */ /* var */arr: Array<any>;

        /* internal */ /* var */_getRule: Boolean;
    }
